<template>
    <view class="page">
        <u-tabbar v-model="current" :show="showTab" :bg-color="bgColor" :border-top="borderTop" :list="list" :inactive-color="inactiveColor"
            :activeColor="activeColor" @change="beforeSwitch"></u-tabbar>
    </view>
</template>
  
  <script>
export default {
    props: {
        current: {
            type: Number,
            default: 0,
            required: true,
        },
    },
    data() {
        return {
            showTab: true,
            bgColor: "#ffffff",
            borderTop: true,
            list: [
            ],
            unLoginList: [
                {
                    iconPath: "/static/tabBarMini/tab_01.png",
                    selectedIconPath: "/static/tabBarMini/tab_02.png",
                    text: "首页",
                    pagePath: "/pages/index/index",
                },
                {
                    iconPath: "/static/tabBarMini/tab_09.png",
                    selectedIconPath: "/static/tabBarMini/tab_10.png",
                    text: "我的",
                    pagePath: "/pages/my/my",
                },
            ],
            loginList: [
                {
                    iconPath: "/static/tabBarMini/tab_01.png",
                    selectedIconPath: "/static/tabBarMini/tab_02.png",
                    text: "首页",
                    pagePath: "/pages/index/index",
                },
                {
                    iconPath: "/static/tabBarMini/tab_07.png",
                    selectedIconPath: "/static/tabBarMini/tab_08.png",
                    text: "商城",
                    pagePath: "/pages/mall/index", // 添加页面路径
                },
                {
                    iconPath: "/static/tabBarMini/tab_11.jpg",
                    selectedIconPath: "/static/tabBarMini/tab_12.jpg",
                    text: "购物车",
                    pagePath: "/pages/mall/car", // 添加页面路径
                },
                {
                    iconPath: "/static/tabBarMini/tab_09.png",
                    selectedIconPath: "/static/tabBarMini/tab_10.png",
                    text: "我的",
                    pagePath: "/pages/my/my",
                },
            ],
            inactiveColor: "#9b9b9b",
            activeColor: "#2e996f",
            isLogin: false
        };
    },
    created() {
        console.log(uni.getStorageSync("token"),'tabbar')
        this.isLogin = uni.getStorageSync("token") ? true : false
        this.getList()
    },
    methods: {
        getList() {
            this.list = this.isLogin ? this.loginList : this.unLoginList
        },
        beforeSwitch(index) {
            // if (index === 2) {
            //     this.navigateToExternalMiniProgram();
            // }
        },
        navigateToExternalMiniProgram() {
            uni.navigateToMiniProgram({
                appId: "wx4742355c53cdf3d6",
                path: "/pages/index/index",
                success() {
                    console.log("跳转到其他小程序成功");
                },
                fail(err) {
                    console.error("跳转到其他小程序失败:", err);
                },
            });
        },
    },
};
</script>
<style scoped lang="scss">
</style>